Repository navigation
feat(rust): add cargo meta gen run engine and entity generator - #608
Merged
Merged
Conversation
…ator The Rust port can now generate code. Two new workspace crates: - metaobjects-codegen: the run engine (ADR-0064) and the `entity` generator. The engine writes a generated file only when its bytes changed, saves the hash manifest once per run and only when a record changed, and skips the whole run when the model hash tree, project config, engine build, generator identities and flags match the stored key and every recorded output is intact. `entity` writes one crate per metadata package: serde structs for entities and value objects, enums, Box only where a by-value cycle needs it, path dependencies for cross-package references, already rustfmt-clean. - metaobjects-cli: the `cargo-meta` binary, so `cargo meta gen` works. Rust differs from the other ports on purpose: no three-way merge (a hand-edited generated file is refused), outputs must be inside the project, and there is no verify, eject or template tier yet. Tests: golden text, `cargo check` + rustfmt + serde round trip on generated crates, run-engine, the shared skip-conformance corpus, CLI. gen_bench records time per stage with no thresholds; the rust lane prints it.
The compile tests passed --offline, so they only worked on a machine whose cargo cache already held serde (a dependency of the generated crates alone). On a fresh CI runner they failed to download it. The copied lockfile still pins serde, so dropping --offline changes no version.
dmealing
force-pushed
the
fm/mo-rust-run-engine-gen
branch
from
November 19, 2026 05:54
b2908bc to
b866cdc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Changed
The Rust port (ADR-0065, preview, unpublished) can now generate code: a run engine, a
cargo meta gencommand and theentitygenerator.metaobjects-codegen: the run engine (ADR-0064) and theentitygenerator. The engine writes a generated file only when its bytes changed, saves.metaobjects/.gen-state/.hashes.jsononce per run and only when a record changed, and skips the whole run (nothing rendered, nothing written, not even the manifest) when the model hash tree, project config, engine build, generator identities and flags match the stored key and every recorded output is intact.entitywrites one crate per metadata package: serde structs for entities and value objects, enums,Boxonly where a by-value cycle needs it, path dependencies for cross-package references; the output is already rustfmt-clean.metaobjects-cli: thecargo-metabinary, so cargo's external-subcommand rule makescargo meta genwork (cargo-meta gentoo).publish = falseeverywhere; no new crates.io dependency (SHA-256 is hand-rolled).metaobjectscrate: visibility only. The loader's@objectRefresolver is nowpuband#[doc(hidden)], marked generator-internal and not a stable API, so the generator binds a reference exactly as the loader does and the 1.3.0 public surface does not grow. No logic change.scripts/ci-local.shruns agen_benchstep in therustlane (record only). CHANGELOG entry under[Unreleased]. The pipeline's document step also touchedREADME.md,docs/CONFORMANCE.md,docs/features/cli.md, the skip-corpus README and ADR-0065 to describe what this ships; PR 607 touches some of the same files, so expect a rebase conflict where they meet (keep both sides).Where Rust deliberately differs from the other ports
Manifest and skip behaviour:
hand-edit-keptdoes not apply to Rust, andgenerated-file-editedmeans "the run is attempted and the file is refused"..hashes.json, project-relative/paths, SHA-256 of the UTF-8 content, 2-space JSON with a trailing newline). Rust does require the output directory to be a sub-directory of the project (the project root is rejected), so every key is project-relative and the stale-file sweep can never touch another port's records..fingerprint-rust.json(uncommitted, versioned by its ownformatfield). It deliberately drops the TypeScript fingerprint'sextrasanduntrackedarrays: nothing in this port populates or reads them (generator extra inputs are folded straight into the key, and every output is inside the project). The file is internal to this port, so the shape difference is invisible to the other ports.metaobjects-codegenandmetaobjectssources, so a skipped run pays nothing for it.cargo meta gen Order) never skip, never store a key and sweep nothing. They emit every file of each crate that contains a selected object plus the transitive closure of the crates those depend on (unchanged bytes are never rewritten), so the result compiles. An entity name that matches two objects is an error;::Nameselects a package-less one.template-edited,template-added(no templates),owned-generator-edited(noeject),hand-edit-kept(no merge),ci(noverify).engine-changedis exercised by altering the stored key, since the engine identity is a compile-time hash.verify,eject, templates, client or HTTP generators, relationships/projections/reports in the output.Per-stage timing (
gen_bench, 20x fitness project, 680 files in 20 crates, release build, median of 9; ms; record only, no thresholds)The skip saves render and write only; load and plan (hashing the model) are about 40 of the roughly 45 ms. There is no earlier generation benchmark to compare against, so the comparison is the first run against the no-change run. An unchanged project rewrites no file and no manifest.
Testing
cargo fmt --check,cargo clippy --locked --all-targets -- -D warningsandcargo test --lockedpass inserver/rust; all 526 shared metamodel fixtures still pass. New: a golden test of a two-package model's text; a test that generates that model and the fitness model and runscargo check,rustfmt --checkand a serde round trip on the crates (including a named first run and a three-deep dependency chain); run-engine tests (unchanged bytes not rewritten, one manifest save, skip, refusal, orphan sweep, named runs); the shared skip-conformance corpus; the loader-agreement test for@objectRef; and CLI tests.Validation
no-mistakes took two runs on this branch. Run 1 passed its own steps (six review rounds; every finding fixed: reference resolution now reuses the loader's resolver, named runs emit dependency crates,
::Nameselects a package-less object, a project-root output directory is rejected, the dead fingerprint fields were removed, help text corrected). The forge CI then failed on therustlane: the generated-cratecargo checktests passed--offline, and a fresh runner has no cachedserde(a dependency of the generated crates only), so they could not download it. Run 2 dropped--offline(proved with an empty cargo cache) and also fixed what its review and document steps found: two packages whose names map to one crate name could silently merge through a shared enum (nowERR_NAME_COLLISION, with edge tests), and a stale "does not exist" message in the cross-port bench script. All forge checks pass on the final head. Two document findings in run 1 were ignored on purpose (fit-assessment wording; ADR-0065's status, which PR 607 has since changed).Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed ✅
server/rust/metaobjects-codegen/src/entity.rs:417- Two packages can silently merge into one crate when a shared enum is involved. Plan::build checksc.package != pkg(ERR_NAME_COLLISION) only for struct-bearing crates (lines 268-283). The shared-enum loop (lines 410-423) never compares packages. Trace: packagea::bdeclares an entity, and packagea_bdeclares an abstract sharedfield.enumthat a field consumes. Both map to cratea_bviacrate_name. The enum is pushed into thea_bcrate planned fora::b, so output has no error, one crate, and a Cargo.toml/lib.rs describinga::b. The same hole exists between two packages that each own only shared enums, becausec.packagestays whichever came first. Fix: in the shared-enum loop, when the crate entry already has a non-empty package (or any struct/shared enum) and it differs frompkg, return the same ERR_NAME_COLLISION error. Siblings: none; this loop and the struct loop are the only two places a crate entry is created.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
cargo meta gen Invoiceemits the cross-crate closure and compiles; a bare name shared by a package-less and a packaged object errors, while ::Name and app::Foo each se…scripts/ci-local.sh --affected --strict-toolchainsBaseline (not re-run):scripts/ci-local.sh --affected --strict-toolchainspassed at e760a185dcargo build -p metaobjects-cli --offline(up to date)S1:cargo meta gen --timingson fresh project (metaobjects/meta.shop.json + meta.billing.json, package shop and shop::billing) -> exit 0, 11 files createdS1:cargo check --offlinein generated/shop_billing -> exit 0 (shop path dep compiled)S2: secondcargo meta gen --timingsunchanged ->gen: skipped, nothing changedexit 0, stat mtimes of all generated files identical before/afterS2: edit Category (added required field slug) ->1 updated, 10 unchanged, only generated/shop/src/category.rs contains slug; cargo check shop_billing exit 0S3:cargo meta gen Invoiceon fresh project -> exit 0, 11 files (shop_billing + shop closure);cargo checkshop_billing exit 0S3: package-less Foo + app::Foo:cargo meta gen Foo-> exit 1 ERR_NAME_COLLISION with hint naming::Nameandpkg::Name;cargo meta gen ::Foo-> package-less model crate only;cargo meta gen app::Foo-> app crate only; cargo check model and app both exit 0🔧 **Document** - 1 issue found → auto-fixed ✅
scripts/bench-load/stages.py:353- Rust.prepare raises NotAvailable with the text "not available yet:cargo meta gendoes not exist". The command now exists, so the text is stale. It is a runtime string, not a doc, so I left it. The fix is a one-line wording change to name the missing cargo-meta binary instead.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.